package com.gs.view.entrate.admin;

import java.sql.SQLException;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.gs.Controllore;
import com.gs.R;
import com.gs.business.backup.RecuperaBackup;
import com.gs.business.backup.SaveBackup;
import com.gs.business.comadi.categorie.CommandDeleteAllCategorie;
import com.gs.business.comadi.entrate.CommandDeleteAllEntrate;
import com.gs.business.comadi.uscite.CommandDeleteAllSpese;
import com.gs.business.comadi.utenti.CommandDeleteAllUtenti;
import comi.gsi.view.MyBaseActivity;

public class AdminView extends MyBaseActivity {

	private Button btnDelSpese = null;
	private Button btnDelEntrate = null;
	private Button btnDelCategorie = null;
	private Button btnDelGruppi = null;
	private Button btnDelUtenti = null;
	private Button btnDelDb = null;
	private Button btnInsCateogorie = null;
	private Button btnInsGruppi = null;
	private Button btnSaveBackUp = null;
	private Button btnRecuperaBackUp = null;

	@Override
	protected int getIdLayout() {
		return R.layout.admin;
	}

	@Override
	protected void myOnCreate(final Bundle savedInstanceState) {
		
		btnSaveBackUp = (Button) lazyLoad(btnSaveBackUp, R.id.btnSaveBackup);
		btnSaveBackUp.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				final Intent i = new Intent(v.getContext(), SaveBackup.class);
				v.getContext().startActivity(i);
				
			}
		});
		
		btnRecuperaBackUp = (Button) lazyLoad(btnRecuperaBackUp, R.id.btnRecuperaBackup);
		btnRecuperaBackUp.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				final Intent i = new Intent(v.getContext(), RecuperaBackup.class);
				v.getContext().startActivity(i);
				Toast.makeText(AdminView.this, "BackupRecuperato", Toast.LENGTH_SHORT).show();
			}
		});
		
		btnDelSpese = (Button) lazyLoad(btnDelSpese, R.id.adminBtnDelSpese);
		btnDelSpese.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(final View arg0) {
				if (Controllore.invocaComando(new CommandDeleteAllSpese())) {
					Toast.makeText(AdminView.this, "Tutte le spese eliminate", Toast.LENGTH_SHORT).show();
				}
			}
		});

		btnDelEntrate = (Button) lazyLoad(btnDelEntrate, R.id.adminBtnDelEntrate);
		btnDelEntrate.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(final View arg0) {
				if (Controllore.invocaComando(new CommandDeleteAllEntrate())) {
					Toast.makeText(AdminView.this, "Tutte le entrate eliminate", Toast.LENGTH_SHORT).show();
				}
			}
		});

		btnDelCategorie = (Button) lazyLoad(btnDelCategorie, R.id.adminBtnDelCategorie);
		btnDelCategorie.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(final View arg0) {

				try {
					if (Controllore.invocaComando(new CommandDeleteAllCategorie())) {
						Toast.makeText(AdminView.this, "Tutte le categorie eliminate", Toast.LENGTH_SHORT).show();
					}
				}
				catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				catch (InstantiationException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				catch (IllegalAccessException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				catch (ClassNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});

		btnDelGruppi = (Button) lazyLoad(btnDelGruppi, R.id.adminBtnDelGruppi);
		btnDelGruppi.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(final View arg0) {
				Toast.makeText(AdminView.this, "Non implementato", Toast.LENGTH_SHORT).show();
			}
		});

		btnDelUtenti = (Button) lazyLoad(btnDelUtenti, R.id.adminBtnDelUtenti);
		btnDelUtenti.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(final View arg0) {
				if (Controllore.invocaComando(new CommandDeleteAllUtenti())) {
					Toast.makeText(AdminView.this, "Tutte le spese eliminate", Toast.LENGTH_SHORT).show();
				}
			}
		});

		btnDelDb = (Button) lazyLoad(btnDelDb, R.id.adminBtnDelDb);
		btnDelDb.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(final View arg0) {
				Toast.makeText(AdminView.this, "Non implementato", Toast.LENGTH_SHORT).show();
			}
		});

		btnInsCateogorie = (Button) lazyLoad(btnInsCateogorie, R.id.adminBtnInsCategorie);
		btnInsCateogorie.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(final View arg0) {
				Toast.makeText(AdminView.this, "Non implementato", Toast.LENGTH_SHORT).show();
			}
		});

		btnInsGruppi = (Button) lazyLoad(btnInsGruppi, R.id.adminBtnInsGruppi);
		btnInsGruppi.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(final View arg0) {
				Toast.makeText(AdminView.this, "Non implementato", Toast.LENGTH_SHORT).show();
			}
		});
		
	}

}
